<!--
  底部导航按钮组件
  一个slot放一个具体内容
-->
<template>
    <div class="tab-bar-item" @click="btClick">
      <div v-if="isActive"><slot name="item-img-active"></slot></div>
      <div v-else><slot name="item-img"></slot></div>
      <div :class="{active: isActive}"><slot name="item-text"></slot></div>
    </div>
</template>

<script>
export default {
  name: "TabBarItem",
  //用接收来自传入的内容
  props: {
    path: String
  },
  data(){
    return {
      // isActive: true
    }
  },
  computed: {
    isActive(){
      //判断活跃的item是否等于当前path
      return this.$route.path.indexOf(this.path) !==-1;
    }
  },
  methods: {
    btClick(){
      // console.log("点击了");
      //当点击时切换路径跳转
      this.$router.replace(this.path);
    }
  }
}
</script>

<style scoped>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 13px;
}
.tab-bar-item img{
  width: 22px;
  height: 22px;
  padding-top: 3px;
  vertical-align: middle;
  margin-bottom: 2px;
}
.active{
  color: #d4237a;
}
</style>
